﻿@model CZTopComputers.Models.TicketViewModel

@{
    ViewBag.Title = "Ticket Index";
}

<h2>Tickets</h2>
<div id="nav">
      <ul>
        <li class="cat">Pages</li>
        @for (int i = 1; i <= Model.PagingInfo.TotalPages; i++)
        {
    <li>@Html.ActionLink("Page " + i.ToString(), null, new { controller = "Ticket", action = "Index", page = i })</li>
        }
        <!--li><a href="http://www.free-css.com/">Cat 1</a></li>
        <li><a href="http://www.free-css.com/">Cat 2</a></li>
        <li><a href="http://www.free-css.com/">Cat 3</a></li>
        <li><a href="http://www.free-css.com/">Cat 4</a></li>
        <li><a href="http://www.free-css.com/">Cat 5</a></li-->
      </ul>
    </div><br/>
<table width="100%">
@foreach (var t in Model.Tickets)
{
    <tr>
		<td valign="top" style="border-top: 1px solid black">
			<table width="100%">
				<tr>
					<td>
						Ticket Id: @t.ID
					</td>
				</tr>
				<tr>
					<td>
						Customer Name: @t.CustomerName
					</td>
				</tr>
				<tr>
					<td>
						Customer Phone: @t.CustomerPhone
					</td>
				</tr>
				<tr>
					<td>
						@Html.ActionLink("Delete this ticket", "Delete", new { ticketID = t.ID })
					</td>
				</tr>
			</table>
		</td>
		<td style="border-top: 1px solid black">
			<table width="100%">
	@foreach (var prodID in Model.TicketContains.Where(c => c.TicketID == t.ID).Select(c => c.ProductID))
    {

        var prod = Model.Products.FirstOrDefault(p => p.ID == prodID);
        if (prod != null)
        {
						@:<tr>
							@:<td>
								Html.RenderPartial("ProductSummaryForTicket", prod);
							@:</td>
						@:</tr>
					}
    }
	@foreach (var pcID in Model.TicketContains.Where(c => c.TicketID == t.ID).Select(c => c.CustomPCID))
    {
        if (pcID != null)
        {
            var pc = Model.CustomPCs.FirstOrDefault(p => p.ID == pcID);
            if (pc != null)
            {
							@:<tr>
								@:<td>
									@:<table width="100%">
										@:<tr>
											@:<td>
												Html.RenderPartial("ProductSummaryForTicket", Model.Products.FirstOrDefault(p => p.ID == pc.CaseID));
											@:</td>
										@:</tr>
										@:<tr>
											@:<td>
												Html.RenderPartial("ProductSummaryForTicket", Model.Products.FirstOrDefault(p => p.ID == pc.MotherboardID));
											@:</td>
										@:</tr>
										@:<tr>
											@:<td>
												Html.RenderPartial("ProductSummaryForTicket", Model.Products.FirstOrDefault(p => p.ID == pc.ProcessorID));
											@:</td>
										@:</tr>
										@:<tr>
											@:<td>
												Html.RenderPartial("ProductSummaryForTicket", Model.Products.FirstOrDefault(p => p.ID == pc.MemoryID));
											@:</td>
											@:<td>
												@(pc.MemoryQty + "x")
											@:</td>
										@:</tr>
										@:<tr>
											@:<td>
												Html.RenderPartial("ProductSummaryForTicket", Model.Products.FirstOrDefault(p => p.ID == pc.GraphicsCardID));
											@:</td>
											@:<td>
												@(pc.GraphicsCardQty + "x")
											@:</td>
										@:</tr>
										@:<tr>
											@:<td>
											Html.RenderPartial("ProductSummaryForTicket", Model.Products.FirstOrDefault(p => p.ID == pc.HardDriveID));	
											@:</td>
											@:<td>
											@(pc.HardDriveQty + "x")
											@:</td>
										@:</tr>
										@:<tr>
											@:<td>
											Html.RenderPartial("ProductSummaryForTicket", Model.Products.FirstOrDefault(p => p.ID == pc.PowerSupplyID));	
											@:</td>
										@:</tr>
										@:<tr>
											@:<td>
											Html.RenderPartial("ProductSummaryForTicket", Model.Products.FirstOrDefault(p => p.ID == pc.MediaDriveID));	
											@:</td>
										@:</tr>
									@:</table>
								@:</td>
							@:</tr>
						}
                    }
                }
			</table>
		<//td>
	</tr>
}

</table>
<div id="nav">
      <ul>
        <li class="cat">Pages</li>
        @for (int i = 1; i <= Model.PagingInfo.TotalPages; i++)
        {
    <li>@Html.ActionLink("Page " + i.ToString(), null, new { controller = "Ticket", action = "Index", page = i })</li>
        }
        <!--li><a href="http://www.free-css.com/">Cat 1</a></li>
        <li><a href="http://www.free-css.com/">Cat 2</a></li>
        <li><a href="http://www.free-css.com/">Cat 3</a></li>
        <li><a href="http://www.free-css.com/">Cat 4</a></li>
        <li><a href="http://www.free-css.com/">Cat 5</a></li-->
      </ul>
    </div><br/>